﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SeriesUpdates
{
    public partial class Edit : Form
    {
        public Edit()
        {
            InitializeComponent();

            ToolTip btnEditTooltip = new ToolTip();
            btnEditTooltip.SetToolTip(btn_save, "Sauvegarder");
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            this.seriesTableAdapter.Fill(this.seriesUpdatesDataSet.series);
        }

        private void _saveChanges()
        {
            this.seriesTableAdapter.Update(this.seriesUpdatesDataSet.series);
            this.seriesUpdatesDataSet.AcceptChanges();
            this.seriesTableAdapter.Fill(this.seriesUpdatesDataSet.series);

            string messageSuccess = "Base de données modifiée avec succès !";

            Success frmcompRegis = new Success(messageSuccess);
            frmcompRegis.ShowDialog();

            if(frmcompRegis.DialogResult == DialogResult.Cancel)
            {
                this.Close();
            }
        }

        private void btn_save_Click(object sender, EventArgs e)
        {
            this.btn_save.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255);

            this._saveChanges();
        }

        private void dataGridView_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
        {
            this._saveChanges();
        }

        private void dataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {
            MessageBox.Show(e.Exception.Message, "Oooops", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        private void dataGridView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            using (SolidBrush b = new SolidBrush(dataGridView.RowHeadersDefaultCellStyle.ForeColor))
            {
                e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 4);
            }
        }
    }
}
